package com.itheima.edu.day25DataGramDemo.day25_1UUID;

import com.itheima.edu.day25DataGramDemo.day25_1UUID.test.ThreadSocket;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.*;

public class ReceiveUpdate {
    public static void main(String[] args) throws IOException {

        //创建服务器接收端，并与客户端进行连接，指定端口号
        ServerSocket ss = new ServerSocket(10001);

        //加入线程池优化代码
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                3,//核心线程数量
                10,//线程池总量
                20,//临时线程总量
                TimeUnit.SECONDS,//临时线程空闲时间的单位
                new ArrayBlockingQueue<>(5),//阻塞队列
                Executors.defaultThreadFactory(),//创建线程的方式，默认方式
                new ThreadPoolExecutor.AbortPolicy()//任务拒绝策略
        );

        while (true) {
            //连接成功后，返回一个Socket对象用于调用方法
            Socket accept = ss.accept();

            ThreadSocket ts =new ThreadSocket(accept);
//            Thread t = new Thread(ts);
//            t.start();
            pool.submit(ts);
        }
        //ss.close();

    }
}
